package 回溯;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

import java.util.Date;

/**
 * todo
 *
 * @author songZiHao
 * @version 1.0.0
 * @ClassName 求一个树的最大惩罚数2689.java
 * @createTime 2023年10月18日 16:38:00
 */
public class 求一个整数的惩罚数2689 {
	public int punishmentNumber(int n) {
		int sum = 0;
		for (int i = 0; i <= n; i++) {
			int str = i * i;
			if (backTrace(str + "", 0, i)) {
				sum += str;
			}
		}
		return sum;
	}

	public boolean backTrace(String num, int index, int target) {
		//到最后一位,结果为0，则正好
		if (num.length() == index) {
			return target == 0;
		}
		for (int i = index; i < num.length(); i++) {
			int temp = Integer.parseInt(num.substring(index, i + 1));
			//截取的数已经大于了
			if (temp > target) {
				break;
			}
			if (backTrace(num, i + 1, target - temp)) {
				return true;
			}
		}
		return false;
	}

	/*public static void main(String[] args) throws InterruptedException {
		JSONObject object = JSON.parseObject("{\"beginTime\":1698286826289,\"close\":0}");
		System.out.println(object);
		Date date1 = new Date();
		Thread.sleep(2000);
		Date date2 = new Date();
		System.out.println(date1.before(date2));
	}*/

	/**
	 * 默认情况：0 都显示
	 */
	static int DEFAULT_SITUATION = 0;

	/**
	 * 1 不显示FACEBOOK
	 */
	static int FACEBOOK = 1;

	/**
	 * 10 不显示GOOGLE
	 */
	static int GOOGLE = 1 << 1;

	/**
	 * 100 不显示LINE
	 */
	static int LINE = 1 << 2;

	public static void main(String[] args) {
		System.out.println("DEFAULT: " + Integer.toBinaryString(DEFAULT_SITUATION));
		System.out.println("FACEBOOK: " + Integer.toBinaryString(FACEBOOK));
		System.out.println("GOOGLE: " + Integer.toBinaryString(GOOGLE));
		System.out.println("LINE: " + Integer.toBinaryString(LINE));
		System.out.println("LINE|FACEBOOK|GOOGLE: " + Integer.toBinaryString(LINE | FACEBOOK | GOOGLE));
		System.out.println();
	}

}
